package loveATM.atm.Panel;

import loveATM.atm.ATM;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class MenuPanel extends JPanel implements ActionListener {
    private ATM atm;
    private JButton searchBtn = new JButton(new ImageIcon("images/buttonFind.jpg"));
    private JButton saveBtn = new JButton(new ImageIcon("images/buttonSave.jpg"));
    private JButton offBtn = new JButton(new ImageIcon("images/buttonOff.jpg"));
    private JButton modifyBtn = new JButton(new ImageIcon("images/buttonModify.jpg"));
    private JButton getBtn = new JButton(new ImageIcon("images/buttonGet.jpg"));
    private JButton transferBtn = new JButton("转账");

    public MenuPanel(ATM atm){
        this.atm = atm;
        this.setLayout(null);
        this.setOpaque(false);


        saveBtn.setBounds(50,150,140,50);
        saveBtn.addActionListener(this);
        this.add(saveBtn);

        getBtn.setBounds(50,300,140,50);
        getBtn.addActionListener(this);
        this.add(getBtn);

        searchBtn.setBounds(50,450,140,50);
        searchBtn.addActionListener(this);
        this.add(searchBtn);

        modifyBtn.setBounds(1024-190,150,140,50);
        modifyBtn.addActionListener(this);
        this.add(modifyBtn);

        transferBtn.setBounds(1024-190,300,140,50);
        transferBtn.addActionListener(this);
        this.add(transferBtn);

        offBtn.setBounds(1024-190,450,140,50);
        offBtn.addActionListener(this);
        this.add(offBtn);

    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == saveBtn){
            atm.showPanel("save");
        }else if (e.getSource() == offBtn){
            atm.showPanel("login");
        }else if (e.getSource() == getBtn){
            atm.showPanel("get");
        }else if (e.getSource() == searchBtn){
            atm.showPanel("search");
        }else if (e.getSource() == transferBtn){
            atm.showPanel("transferBtn");
        }else if (e.getSource() == modifyBtn){
            atm.showPanel("changePwd");
        }

    }
}
